package com.hesicare.adapter.service.impl;

import com.hesicare.adapter.service.IParseIndicatorService;
import com.hesicare.health.entity.HisIndicatorMidinfo;
import com.hesicare.health.service.IHisIndicatorMidinfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Author 55097
 * @create 2021/11/19 9:03
 */
@Service
public class ParseIndicatorServiceImpl implements IParseIndicatorService {

    @Autowired
    private IHisIndicatorMidinfoService ihisIndicatorMidinfoService;

    private final static Logger log = LoggerFactory.getLogger(ParseIndicatorServiceImpl.class);


    @Override
    public void parseIndicator(Object obList) {
        List<HisIndicatorMidinfo> hisIndicatorMidinfos = (List<HisIndicatorMidinfo>) obList;
        if (hisIndicatorMidinfos != null) {
            Set<String> specimenNoCount = new HashSet<>();
            hisIndicatorMidinfos.stream().forEach(hisIndicatorMidinfo -> {
                List<HisIndicatorMidinfo> hisIndicatorMidinfoList = ihisIndicatorMidinfoService.selectHisIndicatorMidinfoBySpecimenNo(hisIndicatorMidinfo.getSpecimenNo());
                if (!specimenNoCount.contains(hisIndicatorMidinfo.getSpecimenNo()) && hisIndicatorMidinfoList.size() > 0) {
                    return;
                }
                ihisIndicatorMidinfoService.insertHisIndicatorMidinfoService(hisIndicatorMidinfo);
                specimenNoCount.add(hisIndicatorMidinfo.getSpecimenNo());
                log.info("新增实验室检验检查项{}", hisIndicatorMidinfo.toString());
            });
        }
    }
}
